"""
导入dip记录
"""
import json

import pdfplumber

import common

tag = "Dip2"
fields = ["Mdc", "Mop", "Rop"]
server = common.ServerRemoteRelease

if __name__ == "__main__":
    with pdfplumber.open("/Users/zhujianfeng/dip_2_0.pdf") as pdf:
        for page in pdf.pages:
            table = page.extract_table()
            if table is None:
                continue
            skipped_rows_table = table[1:]
            records = []
            for row in skipped_rows_table:
                records.append({
                    fields[0]: row[1],
                    fields[1]: row[3],
                    fields[2]: row[5]
                })
            msg = json.dumps({
                "fields": fields,
                "records": records
            }, ensure_ascii=False)
            print(msg)
            # print(len(msg.encode()))
            common.batch_add(tag, msg, server=server)
